home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 30
/
Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso
/
Aminet
/
dev
/
misc
/
WHDLoad_dev.lha
/
WHDLoad
/
Autodoc
/
whdload.doc
Wrap
Text File
|
1999-02-15
|
61KB
|
1,656 lines
TABLE OF CONTENTS
WHDLoad/--Overview--
WHDLoad/resload_Abort
WHDLoad/resload_Control
WHDLoad/WHDLTAG_CBAF_SET
WHDLoad/WHDLTAG_CBSWITCH_SET
WHDLoad/WHDLTAG_IOERR_GET
WHDLoad/resload_CRC16
WHDLoad/resload_Decrunch
WHDLoad/resload_Delay
WHDLoad/resload_DeleteFile
WHDLoad/resload_DiskLoad
WHDLoad/resload_DiskLoadDev
WHDLoad/resload_FlushCache
WHDLoad/resload_GetFileSize
WHDLoad/resload_ListFiles
WHDLoad/resload_LoadFile
WHDLoad/resload_LoadFileDecrunch
WHDLoad/resload_LoadFileOffset
WHDLoad/resload_ProtectRead
WHDLoad/resload_ProtectReadWrite
WHDLoad/resload_ProtectRemove
WHDLoad/resload_ProtectWrite
WHDLoad/resload_Relocate
WHDLoad/resload_SaveFile
WHDLoad/resload_SaveFileOffset
WHDLoad/resload_SetCACR
WHDLoad.Slave/--Overview--
WHDLoad/--Overview--
The calling conventions for all functions are similar to the OS-Library-
concept. Parameters are provided in registers (except "resload_Abort"),
return codes comes in D0 (on some functions also in D1). After a function call
the registers D0-D1/A0-A1 are destroyed (D0,D1 may contain a returncode) they
are so called scratch registers. All other registers are preserved.
The base of the JMP tower in WHDLoad is similar to a LibraryBase. In
difference to the OS the base must not stand in A6 on calling a function, but
it is recommend to call all functions relative to a address register like
move.l (_resload,pc),a5
JMP (resload_Decrunch,a5)
The resload base is overgiven in A0 on calling the Slave first via
ws_GameLoader (see chapter WHDLoad.Slave/--Overview--).
explanation of some keywords used in this document:
Slave the file which contains the interface code
(see chapter WHDLoad.Slave/--Overview--)
DiskImage a Floppy-disk stored as a file on Harddisk
BaseMem the size of the memory used by the installed program
this value is specified in the Slave : ws_BaseMemSize
this is also the upper bound of chip-mem for the installed
program
logical values used for returncodes (see dos/dos.i):
TRUE = -1 (or better <>0)
FALSE = 0
WHDLoad/resload_Abort
NAME
resload_Abort -- quit and return to operating system
SYNOPSIS
resload_Abort( success, primary, secondary)
(a7) (4,a7) (8,a7)
ULONG ULONG ULONG
FUNCTION
terminates the program and return to OS
INPUTS
success - the reason for terminating
one of TDREASON_#? ,defined in "whdload.i"
depending on this value WHDLoad will continue different
TDREASON_OK
a normal exit will performed
TDREASON_DEBUG
WHDLoad will make a memory dump to .whdl_memory and a
register dump to .whdl_register after this it will exit
TDREASON_#? (except the above)
WHDLoad will show an requester which displays the reason
of failure, the user can now choose between "Quit",
"Restart" and "Make CoreDump"
primary - the primary errorcode, depends on success/TDREASON_#?
TDREASON_DOSREAD,TDREASON_DOSWRITE,TDREASON_DOSLIST,
TDREASON_DISKLOAD,TDREASON_DISKLOADDEV
--> dos-errorcode/trackdisk-errorcode
TDREASON_DEBUG
--> program counter (to write it to the register dump)
secondary - the secondary errorcode, depends on success/TDREASON_#?
TDREASON_DOSREAD,TDREASON_DOSWRITE,TDREASON_DOSLIST
--> pointer to filename
TDREASON_DISKLOAD
--> disk number
TDREASON_DEBUG
--> status register (to write it to the register dump)
EXAMPLE
to simply quit:
;primary and secondary wont be needed
move.l #TDREASON_OK,-(a7)
move.l (_resload,pc),a0
jmp (resload_Abort,a0)
to quit because reading of a file has failed:
move.l a0,-(a7) ;a0 = filename
move.l d0,-(a7) ;d0 = doserror code
move.l #TDREASON_DOSREAD,-(a7)
move.l (_resload,pc),-(a7)
add.l #resload_Abort,(a7)
rts
RESULT
nothing because WHDLoad will never return from this call
BUGS
NOTE
this routine is the only which must called via JMP and not JSR,
because the parameters lies on the stack
(this has the advantage that if success==TDREASON_DEBUG the registers
can preserved)
SEE ALSO
example slaves
WHDLoad/resload_Control
NAME
resload_Control
SYNOPSIS
success = resload_Control(tags)
D0 A0
BOOL STRUCT
FUNCTION
control function of WHDLoad, get variables from WHDLoad,
set variables in WHDLoad depending on the tags in the overgiven
taglist
INPUTS
tags - pointer to a table of tagitems
WHDLTAG_ATTNFLAGS_GET - gets the AttnFlags from systems execbase
WHDLTAG_ECLOCKFREQ_GET - gets the EClockFrequency from systems
execbase
WHDLTAG_MONITOR_GET - gets the used monitor, the value will be
eiter NTSC_MONITOR_ID or PAL_MONITOR_ID
(defined in graphics/modeid.i), the used
monitor depends on execbase.VBlankFrequency
and can set by the user via tooltypes
NTSC and PAL
WHDLTAG_BUTTONWAIT_GET - returns -1 if argument/tooltype ButtonWait
is set, otherwise returns 0
WHDLTAG_CUSTOM1_GET
WHDLTAG_CUSTOM2_GET
WHDLTAG_CUSTOM3_GET
WHDLTAG_CUSTOM4_GET
WHDLTAG_CUSTOM5_GET - returns numerical value of argument/tooltype
Custom1 .. Custom5
WHDLTAG_CBSWITCH_SET - sets callback function to execute on switch
to installed program
WHDLTAG_IOERR_GET - returns dos error code of the last resload
function call
WHDLTAG_VERSION_GET - returns WHDLoad major version number, can be
used to distinguish between different
versions
WHDLTAG_REVISION_GET - returns WHDLoad minor version number, can be
used to distinguish between different
versions
WHDLTAG_BUILD_GET - returns WHDLoad build number, can be used to
distinguish between different versions
WHDLTAG_TIME_GET - returns a pointer to a filled whdload_time
structure as decribed in whdload.i
EXAMPLE
...
clr.l -(a7) ;TAG_DONE
clr.l -(a7) ;data to fill
move.l #WHDLTAG_ATTNFLAGS_GET,-(a7)
move.l a7,a0
move.l (_resload,pc),a2
jsr (resload_Control,a2)
move.w (6,a7),d0 ;D0 = AttnFlags
lea (12,a7),a7 ;restore sp
...
EXAMPLE
...
lea (_tags,pc),a0
move.l (_resload,pc),a2
jsr (resload_Control,a2)
move.w (_attn,pc),d0 ;D0 = AttnFlags
...
_tags
dc.l WHDLTAG_MONITOR_GET
_mon dc.l 0
dc.l WHDLTAG_ATTNFLAGS_GET
dc.w 0 ;padding
_attn dc.w 0
dc.l 0 ;TAG_DONE
RESULT
success is true if all tags in the taglist are correctly processed
GET items in the taglist are filled with the requested data
BUGS
NOTE
requires ws_Version >= 5
SEE ALSO
WHDLoad/WHDLTAG_CBAF_SET
NAME
WHDLTAG_CBAF_SET
SYNOPSIS
cont, adr, data = CBAF(mode, size, pc, adr, data)
D0 A1 A2 D0 D1 A0 A1 A2
LONG APTR APTR LONG LONG APTR APTR APTR
FUNCTION
with this tag a function can be set which will executed from WHDLoad
when an access fault exception occurs which is not handled by WHDLoad
itself, it may be used to locate specific accesses in conjunction with
resload_Protect and to correct invalid accesses in the development
process
with this routine you can catch all access faults except:
- instruction stream faults
- blitterwait and blitsize checks
at the time this routine will be executed the interrupts are disabled
via the sr
the routine MUST not change any register except the registers holding
a return value, it MUST return via RTS
INPUTS
mode - transfer mode of the faulted access
0 - read
1 - modify (only 68040/060)
2 - write
size - operand size of the attempted access
1 - Byte
2 - Word
4 - LongWord
pc - program counter of the instruction which has faulted
adr - the address which has attempted to access
data - valid only on write operations, the given memory address
contains the data which has been tried to write
RESULT
cont - how to continue
0 - terminate, WHDLoad will show a requester notifying the
access fault
1 - proceed, the faulted access will be emulated by the
handler inside great WHDLoad
adr - in case of proceed the address which will be accessed
data - in case of proceed and a write operation a pointer to the data
which will be written
EXAMPLE
if you want to get informed at which point the installed program
writes the value 42 to the address $BABE, you can do this like this:
...
clr.l -(a7) ;TAG_DONE
pea (_af,pc) ;function
move.l #WHDLTAG_CBAF_SET,-(a7)
move.l a7,a0
move.l (_resload,pc),a2
jsr (resload_Control,a2)
lea (12,a7),a7 ;restore sp
moveq #2,d0
lea ($BABE),a0
jsr (resload_ProtectWrite,a2)
...
_af cmp.l #$BABE,a1 ;correct address ?
bne .term
cmp.w #2,d1 ;size
bne .term
cmp.w #42,(a2)
beq .term
moveq #1,d0 ;proceed
rts
.term moveq #0,d0 ;terminate
rts
EXAMPLE
if want you to redirect an access to $24 to the address $300, you can
do this like this:
...
clr.l -(a7) ;TAG_DONE
pea (_af,pc) ;function
move.l #WHDLTAG_CBAF_SET,-(a7)
move.l a7,a0
move.l (_resload,pc),a2
jsr (resload_Control,a2)
lea (12,a7),a7 ;restore sp
moveq #4,d0
lea ($24),a0
jsr (resload_ProtectWrite,a2)
...
_af cmp.l #$24,a1 ;correct address ?
bne .term
lea ($300),a1
moveq #1,d0 ;proceed
rts
.term moveq #0,d0 ;terminate
rts
BUGS
currently only supported on 68030
NOTE
requires ws_Version >= 9
MUST not be used in public releases, for development process only
SEE ALSO
resload_Control
WHDLoad/WHDLTAG_CBSWITCH_SET
NAME
WHDLTAG_CBSWITCH_SET
SYNOPSIS
to be used with resload_Control
FUNCTION
with this tag a function can be set which will executed from WHDLoad
when it switches from the OS to the installed program, the aim is to
give a possebilty to fix the problem that some Custom registers are
destroyed during such a switch
at the time this routine will be executed all interrupts and dma's are
disabled and the installed programs memory is restored
the function MUST not change any register, MUST not use stack and MUST
return via "JMP (A0)"
known registers which will be destroyed during the switch between OS
and installed program are cop2lc, bltafwm and bltalwm, but perhaps
there are more of them
INPUTS
pointer to a function to execute
a pointer equal 0 means that no callback function should be active
EXAMPLE
...
clr.l -(a7) ;TAG_DONE
pea (_cbswitch,pc) ;function
move.l #WHDLTAG_CBSWITCH_SET,-(a7)
move.l a7,a0
move.l (_resload,pc),a2
jsr (resload_Control,a2)
lea (12,a7),a7 ;restore sp
...
_cbswitch move.l (_c2,pc),(_custom+cop2lc)
jmp (a0)
_cb2 dc.l $10e80
RESULT
none
BUGS
NOTE
requires ws_Version >= 7
SEE ALSO
resload_Control
WHDLoad/WHDLTAG_IOERR_GET
NAME
WHDLTAG_IOERR_GET
SYNOPSIS
to be used with resload_Control
FUNCTION
this tag can be used to get the dos errorcode of the last called
resload function, all resload functions except resload_Control will
set/reset this error code
currently there are two resload functions which will set the error
code:
resload_GetFileSize
if a file with the specified name cannot be opened via
dos.Open, the error code will be set to the value returned
from dos.IoErr, so the error code may contain values like
ERROR_OBJECT_NOT_FOUND, ERROR_OBJECT_WRONG_TYPE,
ERROR_READ_PROTECTED or similar stuff from dos/dos.i
the errorcode can be used to distinguish between a file with
size of 0 and a nonexistent file
resload_ListFiles
if the specified buffer to fill is not large enough to hold
all filenames from the scanned directory, the error code will
be set to ERROR_NO_FREE_STORE
INPUTS
none
EXAMPLE
...
clr.l -(a7) ;TAG_DONE
clr.l -(a7) ;data to fill
move.l #WHDLTAG_IOERR_GET,-(a7)
move.l a7,a0
move.l (_resload,pc),a2
jsr (resload_Control,a2)
move.l (4,a7),d0 ;D0 = IoErr
lea (12,a7),a7 ;restore sp
...
RESULT
none
BUGS
NOTE
requires ws_Version >= 8
SEE ALSO
resload_Control
WHDLoad/resload_CRC16
NAME
resload_CRC16 -- calculate ANSI conform 16 bit CRC checksum
SYNOPSIS
checksum = resload_CRC16(length,address)
D0 D0 A0
UWORD ULONG APTR
FUNCTION
calculate ANSI conform 16 bit CRC checksum
mostly used to difference between various program versions
INPUTS
length - length of area to calculate over
address - pointer to area
EXAMPLE
...
lea $1000,a0
move.l #256,d0 ;256 bytes starting at $1000
move.l (_resload,pc),a2
jsr (resload_CRC16,a2)
cmp.w #$f2b7,d0
bne .false_version
...
RESULT
checksum - 16 bit crc
BUGS
NOTE
requires ws_Version >= 3
SEE ALSO
WHDLoad/resload_Decrunch
NAME
resload_Decrunch -- decrunch(unpack) file in memory
SYNOPSIS
size = resload_Decrunch(source, destination)
D0 A0 A1
ULONG APTR APTR
FUNCTION
decrunch packed file in memory
at the moment supported is : "RNC\01", "RNC\02", "IMP!", "ATN!"
INPUTS
source - address of source
destination - destination address (can be equal to source)
EXAMPLE
RESULT
size - the size of the decrunched file or 0 if not crunched or
format not known
BUGS
NOTE
SEE ALSO
resload_LoadFileDecrunch
WHDLoad/resload_Delay
NAME
resload_Delay -- wait some time
SYNOPSIS
resload_Delay(time)
D0
ULONG
FUNCTION
wait the specified time or until a button is pressed, the left and
right mouse button (port 0) and the fire button (port 1) will be
checked, after the time is released or a button is pressed the
function will wait until all buttons has been released
the wait routine is based on the raster beam, but checks the current
display and will therefore wait the correct time on PAL and NTSC
INPUTS
time - time to wait in 1/10 seconds
EXAMPLE
...
moveq #30,d0 ;3 seconds
move.l (_resload,pc),a2
jsr (resload_Delay,a2)
...
RESULT
nothing, all registers are preserved
BUGS
NOTE
in difference to most others resload_#? function this routine is
granted to preserve all registers
SEE ALSO
WHDLoad/resload_DeleteFile
NAME
resload_Delete -- delete file
SYNOPSIS
success,errorcode = resload_DeleteFile(name)
D0 D1 A0
BOOL ULONG CPTR
FUNCTION
deletes the file or directory with the specified name from the
filesystem
INPUTS
name - name of the file/directory to delete
EXAMPLE
...
lea (_name,pc),a0
move.l (_resload,pc),a2
jsr (resload_DeleteFile,a2)
...
_name dc.b "C:WHDLoad",0
RESULT
success - TRUE on success
errorcode - 0 on success
otherwise a dos-errorcode from dos.IoErr()
if WHDLF_NoError is set, the function only returns on success
BUGS
NOTE
requires ws_Version >= 8
SEE ALSO
WHDLoad/resload_DiskLoad
NAME
resload_DiskLoad -- load part from a diskimage
SYNOPSIS
success,errorcode = resload_DiskLoad(offset,size,diskno,dest)
D0 D1 D0 D1 D2 A0
BOOL ULONG ULONG ULONG UBYTE APTR
FUNCTION
load part from a diskimage
INPUTS
offset - offset in diskimage (relative to the beginning)
size - amount of bytes to read
diskno - disk number
dest - destination address
EXAMPLE
...
move.l #880*512,d0 ;from block 880
move.l #2*512,d1 ;2 blocks
moveq #1,d2 ;disk 1
lea $80000,a0 ;destination
move.l (_resload,pc),a2
jsr (resload_LoadDisk,a2)
...
RESULT
success - TRUE on success
errorcode - 0 on success
otherwise a dos-errorcode from dos.IoErr()
if WHDLF_NoError is set, the function only returns on success
BUGS
NOTE
the name of the images must be "disk." followed by the disk number
(ie "Disk.1")
the size of the diskimages is variable, a try to read outside the
image will create a seek error
SEE ALSO
WHDLoad/resload_DiskLoadDev
NAME
resload_DiskLoadDev -- load part from a physical (floppy) drive
SYNOPSIS
success,errorcode = resload_DiskLoadDev(offset, size, dest, tags)
D0 D1 D0 D1 A0 A1
BOOL ULONG ULONG ULONG UBYTE STRUCT
FUNCTION
load a given amount of bytes from a floppy like device
INPUTS
offset - offset on the disk (relative to the beginning)
size - amount of bytes to read (at the moment this must be a
multiple of 512 bytes)
dest - destination address (at the moment this must be aligned
to 512 bytes)
tags - pointer to a taglist (at the moment there are no valid
tags, so this must be NULL)
EXAMPLE
...
move.l #880*512,d0 ;from block 880
move.l #2*512,d1 ;2 blocks
lea $80000,a0 ;destination
sub.l a1,a1 ;tag list
move.l (_resload,pc),a2
jsr (resload_LoadDisk,a2)
...
RESULT
success - TRUE on success
errorcode - 0 on success
otherwise a trackdisk errorcode
if WHDLF_NoError is set, the function only returns on success
BUGS
NOTE
requires ws_Version >= 2
this function should used only in installation slaves !
at the moment all (size,address) must be aligned to 512 bytes due the
restrictions of trackdisk.device
it is planned to improve the function so that any possible diskformat
is readable with it
SEE ALSO
WHDLoad/resload_FlushCache
NAME
resload_FluchCache -- clear caches
SYNOPSIS
resload_FlushCache()
FUNCTION
clear all caches
INPUTS
EXAMPLE
RESULT
BUGS
NOTE
may be called from User or Supervisor mode
may be also called on 68000/68010
it uses CACR on 68020/68030 and CPUSHA BC on 68040/68060
SEE ALSO
resload_FlushCache
WHDLoad/resload_GetFileSize
NAME
resload_GetFileSize -- get size of a file
SYNOPSIS
size = resload_GetFileSize(name)
D0 A0
BOOL CPTR
FUNCTION
get size of a file
can also be used to check if a file does exist
INPUTS
name - a $0 terminated string, the path + name
EXAMPLE
to check if a file exists
...
lea (_name),a0
move.l (_resload,pc),a2
jsr (resload_GetFileSize,a2)
tst.l d0
bne .exist
...
RESULT
size - the size of the file, 0 if does not exist
BUGS
NOTE
this routine return the size from the filesystem, if the file is
cruched and will be loaded later via resload_LoadFileDecrunch
the size will be different, you have been warned !
SEE ALSO
resload_ListFiles
WHDLoad/resload_ListFiles
NAME
resload_ListFiles -- list filenames of a directory
SYNOPSIS
amount,errorcode = resload_ListFiles(buffersize, name, buffer)
D0 D1 D0 A0 A1
ULONG ULONG ULONG CPTR APTR
FUNCTION
write the names of all files in the specified directory to the
buffer, the filenames are separated with a 0-byte
INPUTS
buffersize - the size of the buffer
name - the name of the directory to scan
buffer - pointer to the buffer (the buffer MUST lie inside
the Slave)
EXAMPLE
...
move.l #_bufend-_buf,d0
lea (_savepath,pc),a0
lea (_buf,pc),a1
move.l (_resload,pc),a2
jsr (resload_ListFiles,a2)
...
_buf ds.b 1000
_bufend
_savepath dc.b "/save",0 ;this MUST be a relative path !
RESULT
amount - amount of listed files in the buffer
errorcode - 0 on success
otherwise a dos-errorcode from dos.IoErr()
if WHDLF_NoError is set, the function only returns on success
BUGS
if the buffer was to small you will NOT get an errorcode (the
buffer is filled as far as possible, amount is equal the
number of names in buffer)
NOTE
SEE ALSO
WHDLoad/resload_LoadFile
NAME
resload_LoadFile -- Load specified file
SYNOPSIS
length,errorcode = resload_LoadFile(name, address)
D0 D1 A0 A1
ULONG ULONG CPTR APTR
FUNCTION
load file to the given address
INPUTS
name - pointer to a $0 terminated string
(the string may be located in BaseMem or in the Slave)
address - the address on which the file should loaded
EXAMPLE
lea (_filename),a0
lea $1000.w,a1 ;destination
move.l (_resload,pc),a2
jsr (resload_LoadFile,a2)
RESULT
length - the size of the loaded file
if an error occurs this is NULL
errorcode - 0 on success
otherwise a dos-errorcode from dos.IoErr()
if WHDLF_NoError is set, the function only returns on success
BUGS
NOTE
caches are flushed after this call
SEE ALSO
resload_LoadFileDecrunch
WHDLoad/resload_LoadFileDecrunch
NAME
resload_LoadFileDecrunch -- Load specified file and unpack if crunched
SYNOPSIS
length,errorcode = resload_LoadFileDecrunch(name, address)
D0 D1 A0 A1
ULONG ULONG CPTR APTR
FUNCTION
load file to the given address and unpack if crunched
INPUTS
name - pointer to a $0 terminated string
(the string may be located in BaseMem or in the Slave)
address - the address on which the file should loaded
EXAMPLE
lea (_filename),a0
lea $1000.w,a1 ;destination
move.l (_resload,pc),a2
jsr (resload_LoadFileDecrunch,a2)
tst.l d0
beq .error
RESULT
length - the size of the loaded file
if an error occurs this is 0
errorcode - 0 on success
otherwise a dos-errorcode from dos.IoErr()
if WHDLF_NoError is set, the function only returns on success
BUGS
NOTE
caches are flushed after this call
SEE ALSO
resload_LoadFile, resload_Decrunch
WHDLoad/resload_LoadFileOffset
NAME
resload_LoadFileOffset -- Load data from file with offset
SYNOPSIS
success,error = resload_LoadFileOffset(size, offset, name, address)
D0 D1 D0 D1 A0 A1
BOOL ULONG ULONG ULONG CPTR APTR
FUNCTION
load data from a file at given file offset
INPUTS
size - amount of bytes to read
offset - in file to read from
name - pointer to a 0 terminated string
(the string may be located in BaseMem or in the Slave)
address - of the buffer to load data in
EXAMPLE
move.l #512,d0 ;size
move.l #$4000,d1 ;offset
lea (_save,pc),a0 ;name
lea $5ac20,a1 ;source
move.l (_resload,pc),a2
jsr (resload_LoadFileOffset,a2)
rts
_save dc.b "saved",0
RESULT
success - TRUE on success
errorcode - 0 on success
otherwise a dos-errorcode from dos.IoErr()
if WHDLF_NoError is set, the function only returns on success
BUGS
NOTE
requires ws_Version >= 6
SEE ALSO
WHDLoad/resload_ProtectRead
NAME
resload_ProtectRead -- mark area as read protected
SYNOPSIS
resload_ProtectRead(length, address)
D0 A0
ULONG APTR
FUNCTION
protect the marked area against reading by the processor
INPUTS
length - size of the memory area which will be protected
address - the start address of the memory area
the area to protect must be located inside the BaseMem area
EXAMPLE
...
moveq #4,d0 ;one longword
lea $4070,a0 ;address
move.l (_resload,pc),a2
jsr (resload_ProtectRead,a2)
...
RESULT
a "Exception 'Access Fault'" WHDLoad requester if the protected area
is accessed
BUGS
the amount of different areas is currently limited to 16,
you must not protect the page where the SSP points to, if you do so
an Double Bus Fault will occure because the CPU will be unable to
write the exception stackframe, only reset will recover from a Double
Bus Fault
limitations on MC68020+MC68851:
this hardware is currently not supported
limitations on MC68030:
- 3-byte transfers are not supported (occuring on misaligned
longword accesses to page boundaries eg. "tst.l $fff")
- locked accesses (tas/cas/cas2) are not supported
limitations on MC68040:
this hardware is currently not supported
limitations on MC68060:
- misaligned access are not supported (a misaligned access is an
access which goes trough a page boundary, for example
"tst.l ($ffe)" (assumed 4KByte page size))
- locked transfers are not supported (tas/cas)
- instructions which lie on a protected page and access the
supervisor portion of the status register are executed wrong
(these instructions will always see the trace bit as 1 and the
interrupt level as 7, any modification of the supervisor portion
will have no effect)
- movem instruction may access a protected area without creating a
Access Fault exception (only the first bus cycle of the excution
unit will be verified for matching a protected area)
- move16 and double precision operations (FPU) are unsupported
- a "move (mem),(mem)" with overlapping source and destination
address which generates an Access Fault because Misalignment
will be executed wrong, for example "move.l ($ffc),($ffe)" where
page $1000..$1fff is protected and memory before execution
contains ($ffc)=$11112222,($1000)=$33334444, after execution
$1000 contains $11114444 and not $22224444)
unsupported accesses will result in a "Exception 'Access Fault'"
WHDLoad requester
NOTE
requires ws_Version >= 6
the MMU must be in use by WHDLoad, otherwise you will get WHDLoad
requester "Unacceptible Arguments".
only accesses to the user and supervisor data stream are affected
(this means not affected are: cpu space accesses (eg getting values
from the vector table) and instruction stream accesses)
SEE ALSO
resload_ProtectReadWrite, resload_ProtectWrite, resload_ProtectRemove
WHDLoad/resload_ProtectReadWrite
NAME
resload_ProtectReadWrite -- mark area as read and write protected
SYNOPSIS
resload_ProtectReadWrite(length, address)
D0 A0
ULONG APTR
FUNCTION
protect the selected area against reading and writing by the processor
INPUTS
length - size of the memory area which will be protected
address - the start address of the memory area
the area to protect must be located inside the BaseMem area
EXAMPLE
...
moveq #4,d0 ;one longword
lea $64,a0 ;address
move.l (_resload,pc),a2
jsr (resload_ProtectReadWrite,a2)
...
RESULT
BUGS
the amount of different areas is currently limited to 16
you must not protect the page where the SSP points to, if you do so
an Double Bus Fault will occure because the CPU will be unable to
write the exception stackframe, only reset will recover from a Double
Bus Fault
limitations on MC68020+MC68851:
this hardware is currently not supported
limitations on MC68030:
- 3-byte transfers are not supported (occuring on misaligned
longword accesses to page boundaries eg. "tst.l $fff")
- locked accesses (tas/cas/cas2) are not supported
limitations on MC68040:
this hardware is currently not supported
limitations on MC68060:
- misaligned access are not supported (a misaligned access is an
access which goes trough a page boundary, for example
"tst.l ($ffe)" (assumed 4KByte page size))
- locked transfers are not supported (tas/cas)
- instructions which lie on a protected page and access the
supervisor portion of the status register are executed wrong
(these instructions will always see the trace bit as 1 and the
interrupt level as 7, any modification of the supervisor portion
will have no effect)
- movem instruction may access a protected area without creating a
Access Fault exception (only the first bus cycle of the excution
unit will be verified for matching a protected area)
- move16 and double precision operations (FPU) are unsupported
- a "move (mem),(mem)" with overlapping source and destination
address which generates an Access Fault because Misalignment
will be executed wrong, for example "move.l ($ffc),($ffe)" where
page $1000..$1fff is protected and memory before execution
contains ($ffc)=$11112222,($1000)=$33334444, after execution
$1000 contains $11114444 and not $22224444)
unsupported accesses will result in a "Exception 'Access Fault'"
WHDLoad requester
NOTE
requires ws_Version >= 6
the MMU must be in use by WHDLoad, otherwise you will get WHDLoad
requester "Unacceptible Arguments".
only accesses to the user and supervisor data stream are affected
(this means not affected are: cpu space accesses (eg getting values
from the vector table) and instruction stream accesses)
SEE ALSO
resload_ProtectRead, resload_ProtectWrite, resload_ProtectRemove
WHDLoad/resload_ProtectRemove
NAME
resload_ProtectRemove -- remove protction from memory area
SYNOPSIS
resload_ProtectRemove(length, address)
D0 A0
ULONG APTR
FUNCTION
remove a previously created protection
INPUTS
length - size of the memory area
address - the start address of the memory area
the area must exactly match the previously created area
EXAMPLE
...
moveq #4,d0 ;one longword
lea $64,a0 ;address
move.l (_resload,pc),a2
jsr (resload_ProtectRemove,a2)
...
RESULT
BUGS
NOTE
requires ws_Version >= 6
SEE ALSO
resload_ProtectRead, resload_ProtectWrite, resload_ProtectWrite
WHDLoad/resload_ProtectWrite
NAME
resload_ProtectWrite -- mark area as write protected
SYNOPSIS
resload_ProtectWrite(length, address)
D0 A0
ULONG APTR
FUNCTION
protect the selected area against writing by the processor
INPUTS
length - size of the memory area which will be protected
address - the start address of the memory area
the area to protect must be located inside the BaseMem area
EXAMPLE
...
moveq #4,d0 ;one longword
lea $64,a0 ;address
move.l (_resload,pc),a2
jsr (resload_ProtectWrite,a2)
...
RESULT
BUGS
the amount of different areas is currently limited to 16
you must not protect the page where the SSP points to, if you do so
an Double Bus Fault will occure because the CPU will be unable to
write the exception stackframe, only reset will recover from a Double
Bus Fault
limitations on MC68020+MC68851:
this hardware is currently not supported
limitations on MC68030:
- 3-byte transfers are not supported (occuring on misaligned
longword accesses to page boundaries eg. "tst.l $fff")
- locked accesses (tas/cas/cas2) are not supported
limitations on MC68040:
this hardware is currently not supported
limitations on MC68060:
- misaligned access are not supported (a misaligned access is an
access which goes trough a page boundary, for example
"tst.l ($ffe)" (assumed 4KByte page size))
- locked transfers are not supported (tas/cas)
- instructions which lie on a protected page and access the
supervisor portion of the status register are executed wrong
(these instructions will always see the trace bit as 1 and the
interrupt level as 7, any modification of the supervisor portion
will have no effect)
- movem instruction may access a protected area without creating a
Access Fault exception (only the first bus cycle of the excution
unit will be verified for matching a protected area)
- move16 and double precision operations (FPU) are unsupported
- a "move (mem),(mem)" with overlapping source and destination
address which generates an Access Fault because Misalignment
will be executed wrong, for example "move.l ($ffc),($ffe)" where
page $1000..$1fff is protected and memory before execution
contains ($ffc)=$11112222,($1000)=$33334444, after execution
$1000 contains $11114444 and not $22224444)
unsupported accesses will result in a "Exception 'Access Fault'"
WHDLoad requester
NOTE
requires ws_Version >= 6
the MMU must be in use by WHDLoad, otherwise you will get WHDLoad
requester "Unacceptible Arguments".
only accesses to the user and supervisor data stream are affected
(this means not affected are: cpu space accesses (eg getting values
from the vector table) and instruction stream accesses)
SEE ALSO
resload_ProtectRead, resload_ProtectReadWrite, resload_ProtectRemove
WHDLoad/resload_Relocate
NAME
resload_Relocate -- relocate an executable
SYNOPSIS
size = resload_Relocate(address, tags)
D0 A0 A1
ULONG APTR STRUCT
FUNCTION
relocate an standard AmigaDOS executable im memory
INPUTS
address - of the executable in memory, this is the source and also the
destination address, i.e. this function will relocates the
executable over itself (a multi stepping technique is used)
tags - currently there are no valid tags
EXAMPLE
lea (_main,pc),a0 ;name
lea $400,a1 ;source
move.l (_resload,pc),a2
jsr (resload_LoadFileDecrunch,a2)
lea $400,a0 ;address
sub.l a1,a1 ;tags
jsr (resload_Relocate,a2)
...
jmp $400 ;start the program
_main dc.b "main-program",0
RESULT
size - length of the relocated executable
(maybe be more or less than the executable file, depending on
if there BSS hunks contained)
BUGS
the routine should support all Kick1.3 hunks except OVERLAY, anyway it
is only tested with some simple executables, please report any
problems or bugs
NOTE
currently the function uses ca 4100 bytes stack, perhaps that will
decreased in the future
currently the executabale must contain of not more than 256 hunks (the
OS allows also only 256 hunks)
SEE ALSO
WHDLoad/resload_SaveFile
NAME
resload_SaveFile -- Write buffer as file to disk
SYNOPSIS
success,errorcode = resload_SaveFile(size, name, address)
D0 D1 D0 A0 A1
BOOL ULONG ULONG CPTR APTR
FUNCTION
write buffer to disk
INPUTS
size - amount of bytes to write
name - pointer to a $0 terminated string
(the string may be located in BaseMem or in the Slave)
address - of the buffer
EXAMPLE
move.l #512,d0 ;size
lea (_save,pc),a0 ;name
lea $5ac20,a1 ;source
move.l (_resload,pc),a2
jsr (resload_SaveFile,a2)
_save dc.b "saved",0
RESULT
success - TRUE on success
errorcode - 0 on success
otherwise a dos-errorcode from dos.IoErr()
if WHDLF_NoError is set, the function only returns on success
BUGS
NOTE
SEE ALSO
WHDLoad.Slave/--Overview--
WHDLoad/resload_SaveFileOffset
NAME
resload_SaveFileOffset -- Write buffer to a file
SYNOPSIS
success,error = resload_SaveFileOffset(size, offset, name, address)
D0 D1 D0 D1 A0 A1
BOOL ULONG ULONG ULONG CPTR APTR
FUNCTION
write buffer to a file at given file offset
INPUTS
size - amount of bytes to write
offset - in file to write
name - pointer to a 0 terminated string
(the string may be located in BaseMem or in the Slave)
address - of the buffer
EXAMPLE
move.l #512,d0 ;size
move.l #$4000,d1 ;offset
lea (_save,pc),a0 ;name
lea $5ac20,a1 ;source
move.l (_resload,pc),a2
jsr (resload_SaveFileOffset,a2)
rts
_save dc.b "saved",0
RESULT
success - TRUE on success
errorcode - 0 on success
otherwise a dos-errorcode from dos.IoErr()
if WHDLF_NoError is set, the function only returns on success
BUGS
NOTE
requires ws_Version >= 5
SEE ALSO
WHDLoad/resload_SetCACR
NAME
resload_SetCACR -- setup cpu caches
SYNOPSIS
old = resload_SetCACR(new, mask)
D0 D0 D1
ULONG ULONG ULONG
FUNCTION
modify the cpu caches via CACR (Cache Control Register) and
the MMU tables if MMU is used by whdload
for the address space of BaseMem (other areas may be also affected)
INPUTS
new - new value for the cacr
mask - the bits to change
valid bits are (defined in exec/execbase.i)
CACRF_EnableI - instruction cache
CACRF_EnableD - data cache
EXAMPLE
to enable the instruction cache :
move.l #CACRF_EnableI,d0 ;defined in exec/execbase.i
move.l d0,d1
move.l (_resload,pc),a2
jsr (resload_SetCACR,a2)
lea (_oldcacr,pc),a0
move.l d0,(a0) ;if you need it later
;(obsolete in most cases)
RESULT
old - the content before
BUGS
NOTE
may be called from User or Supervisor mode
may be also called on 68000/68010
all caches are flushed on return
if WHDLoad is launched with the option NOCACHE this routine will
ignore the inputs (no caches can be enabled)
you can enable the instruction cache (CACRF_EnableI) and the data
cache (CACRF_EnableD), the data cache can only enabled if instruction
cache is also enabled
don't wonder if you see in the coredump or in a freezer that caches
are enabled even if not enabled by the slave: if the mmu is used by
whdload and no caches are switched on by the slave, whdload marks the
BaseMem area using the mmu as nocacheable-serialized, and enables both
caches so that the areas of whdload and the slave are still cachable
to increase performance
on the 68030 WriteAllocation is always enabled
SEE ALSO
resload_FlushCache
WHDLoad.Slave/--Overview--
The WHDload.Slave contains the interface code which makes the installed
program able to load his files from harddisk. Additional it should realize
the possibility to quit the program to return to the OS.
FORMAT
is a standard amiga executable
DANGER
the Slave MUST consist of only ONE hunk (ONE section)
the Slave MUST be 100% PC-relative
BACKGROUND
the Slave must be accessible if the OS is active and also if the OS is
off; therefore the Slave must placed outside the BaseMem area;
if the Slave lies after loading in BaseMem (can only occur if no
FastMem is available) WHDLoad will move the Slave to a other memory-
location; this moving is the reason for "pc-relative" and
"only one hunk"
STRUCTURE
at the top of the Slave is "WhdloadSlave" structure, after this
follows the specific code and data
STRUCTURE WhdloadSlave,0
STRUCT ws_Security,4
STRUCT ws_ID,8
UWORD ws_Version
UWORD ws_Flags
ULONG ws_BaseMemSize
ULONG ws_ExecInstall
RPTR ws_GameLoader
RPTR ws_CurrentDir
RPTR ws_DontCache
( LABEL ws_SIZEOF_pre_v4 )
UBYTE ws_keydebug
UBYTE ws_keyexit
( LABEL ws_SIZEOF_pre_v8 )
ULONG ws_ExpMem
LABEL ws_SIZEOF
ws_Security
the code
moveq #-1,d0
rts
to avoid problems if somebody executes the Slave itself
ws_ID
the string "WHDLOADS" for WHDLoad to check if it is a Slave
(use the macro Slave_HEADER defined in whdload.i for ws_Security and
ws_ID)
ws_Version
the version of WHDLoad that is required by the Slave
some resload functions need at least a specific version of
WHDLoad, e.g. to use resload_CRC16 you must set ws_Version
to 3 or higher
on the other side the size of the WhdloadSlave structure
is different for different Slave versions, e.g. if you set
ws_Version to 4 or higher you MUST initialize the fields
ws_keydebug and ws_keyexit and so on
ws_Flags
WHDLF_Disk / WHDLB_Disk
this flag should enabled if the program uses
disk images (the result is an different PRELOAD)
(starting whdload 0.143 it has no longer affect, but should
set because older WHDLoad version, and future changes)
WHDLF_NoError / WHDLB_NoError
if enabled every error occuring in a resload_#? function
lets WHDLoad immedately quit, and prompt an error requester
about the reason
so it is not neccessary that the Slave checks the return
code of a resload_#? function, it can be sure that if the
function returns it was successful (this will make the
slave much simpler)
WHDLF_EmulTrap / WHDLB_EmulTrap
this flag has only effect if the VBR is moved by WHDLoad
(i.e. the machine is at least a 68010 and the tooltype
NoVBRMove is not set)
if the flag is set all "trap #0..15"'s are emulated by the
exception handler in WHDLoad like the autovectors, i.e.
the handler checks if the vector ($80-$bc) is initialized
by the program, and if yes the routine will be called by
the handler
WHDLF_NoDivZero / WHDLB_NoDivZero
this flag has only effect if the VBR is moved by WHDLoad
(i.e. the machine is at least a 68010 and the tooltype
NoVBRMove is not set)
if the flag is set and a "Division by Zero" exception
occurs WHDLoad will not quit with an requester, but a
simple RTE will be performed
this maybe useful if you don't want use the option
NoVBRMove but the demo/game makes a lot of divisions by
zero and you are not able to patch them all
WHDLF_Req68020 / WHDLB_Req68020
this flag indicates that the Slave/installed program
requires at least a MC68020 cpu, WHDLoad will check at
startup if this requirement matches, if it doesn't the
program will be terminated with an appropriate requester
WHDLF_ReqAGA / WHDLB_ReqAGA
this flag indicates that the Slave/installed program
requires at least the AGA chipset, WHDLoad will check at
startup if this requirement matches, if it doesn't the
program will be terminated with an appropriate requester
WHDLF_NoKbd / WHDLB_NoKbd
this flag says WHDLoad, that it doesn't should reply the
keyboard if a key was pressed, this must be used with
programs which doesn't check the keyboard from the PORTS
interrupt ($68), background: in normal operation when
NoVBRMove is inactive, WHDLoad checks if a key was pressed
on each interrupt, if a key has been pressed it checks the
rawkey code against QuitKey, DebugKey and FreezeKey, if it
doesn't match it looks if there is a initialized PORTS
interrupt ($68), if there is no, it replies the keyboard
that the keycode has been received, therefore the installed
program if it checks the keyboard from e.g. the VBI will
never receive any keycode, this flag avoids this behavior
WHDLF_EmulLineA / WHDLB_EmulLineA
this flag has only effect if the VBR is moved by WHDLoad
(i.e. the machine is at least a 68010 and the tooltype
NoVBRMove is not set)
if the flag is set all exceptions "Line-A" (caused by
opcodes starting with %1010) are emulated by the
exception handler in WHDLoad like the autovectors, i.e.
the handler checks if the vector ($28) is initialized
by the program, and if it is the routine which the vector
points to will be called by the handler
WHDLF_EmulTrapV / WHDLB_EmulTrapV
this flag has only effect if the VBR is moved by WHDLoad
(i.e. the machine is at least a 68010 and the tooltype
NoVBRMove is not set)
if the flag is set all exceptions caused by a TrapV
instruction are emulated by the exception handler in
WHDLoad like the autovectors, i.e. the handler checks if
the vector ($1C) is initialized by the program, and if it
is the routine which the vector points to will be called
by the handler
ws_BaseMemSize
the size of the memory that is required by the program
the BaseMemory starts an $00000000 and ends at ws_BaseMemSize
(BaseMemory is always ChipMem)
this value must be multiple of $1000
the valid minimum is $2000 and maximum $200000
ws_ExecInstall
no longer supported, must be set 0
ws_GameLoader
a relative (to the start of the structure) 16-bit pointer
to the start code of the Slave
ws_CurrentDir
a relative (to the start of the structure) 16-bit pointer
to a 0 terminated string which is the name of the path
where all files are stored (sub directory)
if no sub directory is used initialize this with 0
WHDLoad will change into this directory on startup
the path must be relative; you MUST NOT use any fucking lame
assignments
BACKGROUND: if the assignment is not active on runtime the
dos.library will try to show a "Insert Disk ..." requester,
but intuition.library is locked, -> the system will hang
(deadlock) the user has only one alternative -> REBOOT
ws_DontCache
a relative (to the start of the structure) 16-bit pointer
to a 0 terminated string which is a standard AmigaDos
pattern (dos.ParsePattern, dos.MatchPattern)
all files matching this pattern are not cached by WHDLoad
this may be useful for savegames
if you dont want to use set the entry to 0
starting WHDLoad version 0.107 this is no longer required,
because saved files are written to the cache, and if the
same file already exist it will replaced with the new,
anyway the functional is furthermore intact
the following variables are only evaluated by whdload if ws_Version
is set to >= 4
the following variables MUST be initialized if you set ws_Version
to >= 4
ws_keydebug
the raw key code to exit with debug
this variable will be overwritten by WHDLoad if the option
DebugKey= is set in the global config or as CLI argument or
ToolType with the specified value from there
if the Slave provides an own handler to support a debug option
via the keyboard it should use this entry for comparision, so
it will be possible for the user to change the default key
suggestion from the slave
this entry is also used by WHDLoad's internal handler if the
VBR is moved (requires 68010+ and that NoVBRMove is not set)
(recommend is $58 = "F9")
ws_keyexit
the raw key code to exit
similar to ws_keydebug
(recommend is $59 = "F10")
the following variables are only evaluated by whdload if ws_Version
is set to >= 8
the following variables MUST be initialized if you set ws_Version
to >= 8
ws_ExpMem
if the installed program requires expansion memory, the size
must be specified here, WHDLoad will allocate a memory block
of this size and writes a pointer to the start of the
allocated memory back to this entry, the memory is granted to
be aligned to $1000 (4096 bytes), the size specified must be
an multiple of $1000 (4096), if WHDLoad fails to allocate
this memory it terminates with an appropriate error requester,
that means the slave will always get a valid pointer here
CONVENTIONS for ws_GameLoader
the status of the system at the moment of calling ws_GameLoader:
CPU:
SR = $2000 Supervisor-mode, all interrupts enabled
SSP = ws_BaseMemSize at end of BaseMem
USP = SSP-$400 at end of BaseMem - 1024
A0 = ResidentLoader pointer to the resident Jump-Tower
D0-D7/A1-A6 random (D0=$d0d0d0d0 D1=...)
nothing more is interesting from the Slave programmes point of
view. you will program a virtual machine which is a plain
68000. all special registers like VBR,SFC,DFC,CAAR,CACR,MSP,
TC,MMUSR,CRP,SRP,URP,TT0,TT1,DTT0,DTT1,ITT0,ITT1,PCR,BUSCR
are WHDLoad private and MUST NOT BE CHANGED.
BaseMem:
$00000000 = 0
$00000004 = $f0000001 any try to use the execbase should
create a "Address Error" exception
$00000008 - $00000400
= $CCCCCCCC if WHDLoad has moved the VBR else
= Handler the address of a exception handler
inside WHDLoad
$00000400 - ws_BaseMemSize
= $CCCCCCCC this memory fill pattern is used to
easy recognize modified memory
$00001000 = $FFFFFFFE the copper instruction "CWAIT $ff,$1fe"
ExpMem:
the memory is filled with the pattern "$DDDDDDDD"
custom:
dmacon = 0 all dma's off
intena = 0 all interrupts off
cop1lc = cop2lc = $1000
a AGA-machine is switched to OCS
cia's:
------- ciaa ------ ------- ciab ------
pra in = %00000000 pra in = %00000000
pra out = %11111100 pra out = %11111000
ddra = %00000011 ddra = %11000000
prb in = %00000000 prb in = %00000000
prb out = %00000000 prb out = %11111111
ddrb = %00000000 ddrb = %11111111
ta = $21ff ta = $ffff
tb = $21ff tb = $ffff
event = $000000 event = $000000
alarm = $ffffff alarm = execbase.EClockFrequency
sdr = $00 sdr = $00
icr = %00000000 icr = %00000000
icm = %00001000 icm = %00000000
cra = %00000000 cra = %00000000
crb = %00000000 crb = %00000000
SEE ALSO
example Slaves